<script lang='ts' setup>
import request from "@/assets/工具/网络请求"
import { ref } from "vue";
import { useRouter } from 'vue-router';
import TitleBar from '@/components/标题.vue'
import type { UserInfo } from "@/types";
const User = ref({} as UserInfo)
const view1 = useRouter();

const pageBack  = () =>{
    view1.back()
    // 返回上一个页面
}
const returnNow = () =>{
    
    view1.push('login')
}


let validate:boolean ;
// 定义带有索引签名的类型




const sendUserDatail = () => {
   

    // request.doPost('RegServlet',User).then(result =>{
        request.doPost('insertUserInfoServlet',User.value).then(result =>{
        returnNow()

    }).catch(err =>{
        console.log('失败！！')
    })
}





</script>


<template>
    
    <body class="组件根元素">
        <TitleBar title="注册"/>
   <section>
     <!-- 背景颜色 -->
     <div class="color"></div>
        <div class="color"></div>
        <div class="color"></div>
        <div class="box">
            <!-- 背景圆 -->
            <div class="circle" style="--x:0"></div>
            <div class="circle" style="--x:1"></div>
            <div class="circle" style="--x:2"></div>
            <div class="circle" style="--x:3"></div>
            <div class="circle" style="--x:4"></div>
   
        <div class="register-container">
    <h3>用户注册</h3>
   
        <div class="form-row">
            <label for="username">用户名:</label>
            <input type="text" v-model="User.name" id="username" name="username" required>
        </div>
        <div class="form-row">
            <label for="phone">电话:</label>
            <input type="tel" v-model="User.userPhone"  id="phone" name="phone"  >
            
        </div>
        <div class="form-row">
            <label for="password">密码:</label>
            <input type="password" v-model="User.UserPassword" id="password" name="password" required>
        </div>
        
      
       
        <div class="form-row">
            <label  for="sex" >性别:</label>
            <select v-model="User.userSex" id="sex" name="sex"  required>
                <option value="" >请选择</option>
                <option value="男">男</option>
                <option value="女">女</option>
            </select>
        </div>
        <div class="form-row">
            <label for="address">联系地址:</label>
            <input type="text" v-model="User.address" id="address" name="address" required>
        </div>
        
        <div class="form-row">
            <label for="email">电子邮件:</label>
            <input type="email" v-model="User.email" id="email" name="email" required>
        </div>
        <button  @click="sendUserDatail()">注册</button>
        <p  @click="pageBack" id="message">已有账号，去登陆？</p>
    
</div>
</div>
</section>
    </body>

</template>

<style scoped>
#message:hover{
    cursor: pointer;
    color: blue;
    background-color: rgb(174, 174, 174);
    border-radius: 5px;
}
#message{
    display: block;
    line-height:35px;
    text-align: center;
    margin-top: 6px;
    font-size: 20px;
    width: 180px;
    margin-left: 10px;
    color: rgb(180, 180, 181);
}
/* 清除浏览器默认边距，
使边框和内边距的值包含在元素的width和height内 */
 
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}
 
/* 使用flex布局，让内容垂直和水平居中 */
 
section {
    /* 相对定位 */
    position: relative;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    /* linear-gradient() 函数用于创建一个表示两种或多种颜色线性渐变的图片 */
    background: linear-gradient(to bottom, #f1f4f9, #dff1ff);
}
 
/* 背景颜色 */
 
section .color {
    /* 绝对定位 */
    position: absolute;
    /* 使用filter(滤镜) 属性，给图像设置高斯模糊*/
    filter: blur(200px);
}
 
/* :nth-child(n) 选择器匹配父元素中的第 n 个子元素 */
 
section .color:nth-child(1) {
    top: -350px;
    width: 343px;
    height: 600px;
    background: #ff359b;
}
 
section .color:nth-child(2) {
    bottom: -150px;
    left: 100px;
    width: 343px;
    height: 500px;
    background: #fffd87;
}
 
section .color:nth-child(3) {
    bottom: 50px;
    right: 100px;
    width: 343px;
    height: 500px;
    background: #00d2ff;
}
 
.box {
    position: relative;
}
 
/* 背景圆样式 */
 
.box .circle {
    position: absolute;
    background: rgba(255, 255, 255, 0.1);
    /* backdrop-filter属性为一个元素后面区域添加模糊效果 */
    backdrop-filter: blur(5px);
    box-shadow: 0 25px 45px rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.5);
    border-right: 1px solid rgba(255, 255, 255, 0.2);
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    /* 使用filter(滤镜) 属性，改变颜色。
    hue-rotate(deg)  给图像应用色相旋转 
    calc() 函数用于动态计算长度值 
    var() 函数调用自定义的CSS属性值x*/
    filter: hue-rotate(calc(var(--x) * 70deg));
    /* 调用动画animate，需要10s完成动画，
    linear表示动画从头到尾的速度是相同的，
    infinite指定动画应该循环播放无限次*/
    animation: animate 10s linear infinite;
    /* 动态计算动画延迟几秒播放 */
    animation-delay: calc(var(--x) * -1s);
}
 
/* 背景圆动画 */
 
@keyframes animate {
    0%, 100% {
        transform: translateY(-50px);
    }
    50% {
        transform: translateY(50px);
    }
}
 
.box .circle:nth-child(1) {
    top: -50px;
    right: -60px;
    width: 100px;
    height: 100px;
}
 
.box .circle:nth-child(2) {
    top: 150px;
    left: -100px;
    width: 120px;
    height: 120px;
    z-index: 2;
}
 
.box .circle:nth-child(3) {
    bottom: 50px;
    right: -60px;
    width: 80px;
    height: 80px;
    z-index: 2;
}
 
.box .circle:nth-child(4) {
    bottom: -80px;
    left: 100px;
    width: 60px;
    height: 60px;
}
 
.box .circle:nth-child(5) {
    top: -80px;
    left: 140px;
    width: 60px;
    height: 60px;
}
.phonenu{
   display: block;
   display: flex;
      background-color: lightblue;
      padding: 5px;
      margin-right: 10px;
      font-size: 12px;
}
        /* body {
            margin: 0;
            height: 100vh;
            animation: sunsetGradient 12s ease infinite;
            background: linear-gradient(135deg, #ff9a9e, #fad0c4);
            background-size: 200% 200%;
        }

        @keyframes sunsetGradient {
            0% {
                background-position: 0% 50%;
            }

            50% {
                background-position: 100% 50%;
            }

            100% {
                background-position: 0% 50%;
            }
        }
body {
    font-family: Arial, sans-serif;
   
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    margin: 0;
} */

.register-container {
    background-color: #f5f0e1;
    padding: 20px;
    border-radius: 5px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    width: 320px; /* 设置注册表单的宽度 */
    box-sizing: border-box;
}

h3 {
    text-align: center;
    padding-bottom: 20px;
}

.form-row {
    display: flex; /* 使用 Flexbox 来水平排列 */
    align-items: center; /* 垂直居中对齐 */
    margin-bottom: 10px; /* 每个信息行之间的间距 */
}
#sex{
    border: none;
}
label {
    flex: 0 0 100px; /* 标签部分占据固定宽度 */
    margin-right: 10px; /* 标签和输入框之间的间距 */
    font-size: 20px;
}

input, select,#sex {
    flex: 1; /* 输入框和下拉框占据剩余的空间 */
    padding: 0px;
    box-sizing: border-box; /* 包含padding在宽度中 */
    background-color:rgb(253, 243, 245);
    box-sizing: border-box;
}
input ,#sex{
    border:none;
    border-bottom:2px dashed  pink;
    border-radius:5px;
    font-size: 16px;
    height: 30px;
    width: 140px;
}

button {
    width: 100%;
    padding: 10px;
    background-color: #28a745;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    margin-top: 10px; /* 按钮与表单的间距 */
    font-size: 20px;
}

button:hover {
    background-color: #218838;
}

#message {
    text-align: center;
    color: red;
}
</style>
